﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;

namespace map.member.order
{
    public partial class buy_3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind1();
            }
        }
        private void bind1()
        {
            taobaotrade t = taobaotrade.Find(" buyer_nick = '"
                + AliApi.appUserId + "' and taobaostatus = '"+TRADE_STATUS .Buyer_Order  +"'"
                + " and cbtrantype != '"+TRADE_TranType.PostBySelf +"'"); 
            WebPager1.DataSource = t.MyTable;
            WebPager1.DataBind();
        }

        protected void WebPager1_PageIndexChanged(object sender, RuleCode.Controls.PageChangedEventArgs e)
        {
            WebPager1.CurrentPageIndex = e.NewPageIndex;
            bind1();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string id = e.CommandArgument.ToString();
            if (e.CommandName == "pay")
            {
                Response.Redirect(ResolveUrl("~/member/order/buy_pay.aspx?type=0&id="+id));
                //taobaotrade ui = taobaotrade.Find(" recid = " + id);
                //cbuser u = cbuser.u();
                //double need = zfunction.str2double(ui.taobaopayment.ToString());
                //double have = zfunction.str2double(u.cbmoney.ToString());
                //if (have < need)
                //{
                //    MessageBox.Show(this.UpdatePanel1, "你的余额不够.");
                //    return;
                //}
                //if (ui.taobaostatus.ToString() != TRADE_STATUS.Buyer_Order)
                //{
                //    MessageBox.Show(this.UpdatePanel1, "该订单已经支付,无需再付款,操作取消.");
                //    return;
                //}
                //cbmoneytrans mt = cbmoneytrans.Find("1=2");
                //mt.New();
                //mt.cbuserid.Value = ui.buyer_nick .ToString();
                //mt.cbmoney.Value = -need ;
                //mt.cbmoneytrantype.Value = MONEY_TransType .BuyOut ;
                //mt.jccreatedate.Value = DateTime.Now;
                //mt.jccreatetime.StringValue = DateTime.Now.ToLongTimeString();
                //mt.jcdesc.Value = ui.RECID.ToString()+" "+ui.taobaoname.ToString();
                //mt.NoYes_dongjie.Value = RuleCode.Enum.NoYes.No;
                //mt.RefTable.Value = "taobaotrade";
                //mt.RefRecID.Value = id;
                //mt.Insert();
                //u.cbmoney.Value = u.cbmoney.Value - need;
                //u.cbmoneyF.Value = u.cbmoneyF.Value - need;
                //u.Modify();

                //cbmoneytrans mt2 = cbmoneytrans.Find("1=2");
                //mt2.New();
                //mt2.cbuserid.Value = ui.seller_nick.ToString();
                //mt2.cbmoney.Value = need;
                //mt2.cbmoneytrantype.Value = MONEY_TransType.Block  ;
                //mt2.jccreatedate.Value = DateTime.Now;
                //mt2.jccreatetime.StringValue = DateTime.Now.ToLongTimeString();
                //mt2.jcdesc.Value = ui.RECID.ToString() + " " + ui.taobaoname.ToString();
                //mt2.NoYes_dongjie.Value = RuleCode.Enum.NoYes.Yes ;
                //mt.RefTable.Value = "taobaotrade";
                //mt.RefRecID.Value = id;
                //mt2.Insert();

                //cbuser u2 = cbuser.Find(" cbuserid = '" + ui.seller_nick.ToString() + "'");
                //u2.cbmoneyD.Value += need;
                //u2.Modify();


                //ui.taobaostatus.Value =  TRADE_STATUS .Buyer_Pay ;
                //ui.Modify();
                //MessageBox.Show(this.UpdatePanel1, "操作成功,你支付的金额为:"+need.ToString());
                //bind1();    

            }
        }
    }
}
